package com.iflytek.iot.platform.util;

import cn.zull.tracing.core.model.DefaultTraceLog;
import com.alibaba.fastjson.JSON;
import com.iflytek.iot.platform.tracing.send.SendLogByFlume;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Map;


/**
 * 日志上传flume
 */
@Slf4j
@Component
public class LogBackUtil {
    /**
     * 是否发送全链路到flume
     */
    @Value("${iot.trace.flume.enable:true}")
    private boolean enableFlume;

    public void sendLog(DefaultTraceLog traceLog) {
        String traceLogString = JSON.toJSONString(traceLog);
        log.info("[全链路日志]  traceId:{} {}", traceLog.getTraceId(), traceLogString);
        if (enableFlume) {
            SendLogByFlume.sendLog(traceLogString);
        }
    }

    public static void sendLog(String logType, Map<String, String> map, String sequenceNo) {
        log.warn("[发送flume] type:{}", logType);
        SendLogByFlume.sendLog(logType, map, sequenceNo);
    }

}
